<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!doctype html>
<html class="no-js">
<head>
    <%@ include file="./../common/meta.jsp" %>
    <style>
        .order-main {
            padding: 20px;
        }

        #orderInfo td {
            height: 35px;
        }

        .am-btn {
            margin-top: 20px;
        }

        .info-txt,
        .info-txt2 {
            font-weight: bold;
            padding-left: 15px;
        }

        .info-txt2 {
            padding-left: 40px;
        }
    </style>
</head>
<body>
<header data-am-sticky class="am-header am-header-default am-no-layout">
    <div class="am-header-left am-header-nav">
        <a href="./store-detail.jsp" class="" id="last">
            <i class="am-header-icon am-icon-chevron-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">确认订单</h1>
</header>
<div class="am-g am-content">
    <div class="am-u-sm-12 order-main">
        <div id="orderInfo">
            <table>
                <tbody>
                <tr>
                    <td>图片</td>
                    <td colspan="2"><img width="50px" height="50px" src="" id="image"></td>
                </tr>

                <tr>
                    <td>服务名称</td>
                    <td id="serviceName" class="info-txt"></td>
                </tr>

                <tr>
                    <td>数量</td>
                    <td class="info-txt">x<span id="num">1</span></td>
                </tr>

                <tr>
                    <td>价钱</td>
                    <td id="price" class="info-txt">0</td>
                </tr>

                <tr>
                    <td>龙凤币抵扣</td>
                    <td id="lfbdk" class="info-txt">0</td>
                </tr>

                </tbody>
            </table>
        </div>


        <div class="buy-info">
            <div class="buy-price " id="buyPrice">
                总金额:<span class="info-txt2">￥<span id="totalPrice">0</span>元</span>
            </div>
        </div>
        <button type="button" class="am-btn am-btn-primary am-btn-block" data-am-modal="{target: '#my-popup'}"
                id="submitOrderBtn">提交订单
        </button>
        </button>
    </div>
</div>

<%@ include file="./../common/footerNav.jsp" %>
<%@ include file="./../common/footer.jsp" %>
<script src="../../js/common/common.js"></script>


<script>
    $(function () {
        var id = "<%=request.getParameter("id")%>";
        var catlogid = "<%=request.getParameter("catId")%>";
        var serviceId = "<%=request.getParameter("serviceId")%>";
        var num = "<%=request.getParameter("num")%>";
        var href = $("#last").attr("href");
        $("#last").attr("href", href + "?catId=" + catlogid + "&id=" + id);
        var user = JSON.parse(localStorage.getItem("user"));
        if (user == null || user == "null") {
            window.location.href = './login/login.jsp';

        }
        var url = "/h5GoodShop/getShopProvider?id=" + serviceId + "&accountId=" + user.id;
        $.post(url, function (result) {
            $("#serviceName").text(result.servicename)
            $("#num").text(num)
            $("#price").text(result.servicenowprice)

            var lfbdk = result.lfbdk * num;
            if (result.lfb < lfbdk) {
                lfbdk = result.lfb;
            }

            $("#lfbdk").text(lfbdk)
            $("#totalPrice").text(result.servicenowprice * num - lfbdk)

            if (result.images != null) {
                $("#image").attr("src", result.imageBase + result.images[0])
            }


        })


        $("#submitOrderBtn").click(function () {
            var url = "/h5GoodShop/submitGoodShopOrder";
            $.post(url, {
                account: user.account,
                serviceId: serviceId,
                num: num,
                totalPrice: $("#totalPrice").text()
            }, function (result) {
                if (result.code = '000000') {
                    var id = "<%=request.getParameter("id")%>";
                    var catlogid = "<%=request.getParameter("catId")%>";
                    window.location.href = "./store-pay-order.jsp?id=" + id + "&catId=" + catlogid + "&orderNo=" + result.orderNo + "&pid=" + result.pid;
                } else {
                    alert("提交失败")
                }

            })

        })


    })


</script>

</body>
</html>